package com.stox.core.model;

import java.util.Collections;
import java.util.Date;
import java.util.List;


public class Swing extends Bar{

	private List<Bar> bars;
	private IBar first;
	private IBar last;
	private IBar high;
	private IBar low;
	
	public Swing(List<Bar> bars) {
		this.bars = bars;
		
		for(IBar bar : bars){
			if(first == null) first = bar;
			if(last == null) last = bar;
			if(high == null) high = bar;
			if(low == null) low = bar;
			
			if(first.getDate().after(bar.getDate()))	first = bar;
			if(last.getDate().before(bar.getDate())) last = bar;
			if(high.getHigh() < bar.getHigh()) high = bar;
			if(low.getLow() > bar.getLow()) low = bar;
			
			super.setVolume(super.getVolume()+bar.getVolume());
			super.setTurnover(super.getTurnover() + bar.getTurnover());
			super.setTrades(super.getTrades() + bar.getTrades());
		}
	}

	public List<Bar> getBars(){
		return Collections.unmodifiableList(bars);
	}
	
	public Date getStartDate(){
		return first.getDate();
	}
	
	public Date getEndDate(){
		return last.getDate();
	}
	
	public int getSpan(){
		return Math.abs((int)((getEndDate().getTime() - getStartDate().getTime())/(1000*60*60*24)));
	}
	
	@Override
	public Date getDate() {
		return last.getDate();
	}

	@Override
	public void setDate(Date date) {
		throw new UnsupportedOperationException();
	}

	@Override
	public double getOpen() {
		return first.getOpen();
	}

	@Override
	public void setOpen(double open) {
		throw new UnsupportedOperationException();
	}

	@Override
	public double getHigh() {
		return high.getHigh();
	}

	@Override
	public void setHigh(double high) {
		throw new UnsupportedOperationException();
	}

	@Override
	public double getLow() {
		return low.getLow();
	}

	@Override
	public void setLow(double low) {
		throw new UnsupportedOperationException();
	}

	@Override
	public double getClose() {
		return last.getClose();
	}

	@Override
	public void setClose(double close) {
		throw new UnsupportedOperationException();
	}

	@Override
	public void setVolume(double volume) {
		throw new UnsupportedOperationException();
	}

	@Override
	public double getLast() {
		return last.getLast();
	}

	@Override
	public void setLast(double last) {
		throw new UnsupportedOperationException();
	}

	@Override
	public double getPreviousClose() {
		return first.getPreviousClose();
	}

	@Override
	public void setPreviousClose(double previousClose) {
		throw new UnsupportedOperationException();
	}

	@Override
	public void setTurnover(double turnover) {
		throw new UnsupportedOperationException();
	}

	@Override
	public void setTrades(double trades) {
		throw new UnsupportedOperationException();
	}
	
}
